package cn.tedu.oa.common.controller;

import cn.tedu.oa.common.exception.ServiceException;
import cn.tedu.oa.common.vo.JsonResult;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(AuthorizationException.class)
    @ResponseBody
    public JsonResult doHandleAuthorizationeException(AuthorizationException e){
        e.printStackTrace();
        //封装错误信息
        return new JsonResult(new ServiceException("您没有权限"));
    }
    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public JsonResult doHandleUnauthorizedException(UnauthorizedException e){
        e.printStackTrace();
        //封装错误信息
        return new JsonResult(new ServiceException("您没有权限"));
    }
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public JsonResult doHandleRuntimeException(RuntimeException e) {
        e.printStackTrace();
        return new JsonResult(e);
    }

}
